/*
Copyright 2010 Bryce Alcock

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.com

 */



package com.ecocrypt.proxy.forwarder.gui;

import com.ecocrypt.proxy.forwarder.remote.ForwarderDestination;
import java.util.ArrayList;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author bryce
 */
public class RemoteForwardDestinationTableModel extends AbstractTableModel{



    ArrayList<ForwarderDestination> forwarderDestinations = new ArrayList<ForwarderDestination>();

    public ForwarderDestination getObjectAtLocation(int i){
	if(forwarderDestinations.size()>i){
	    return forwarderDestinations.get(i);
	}
	return null;
    }
    public void addDestination(ForwarderDestination df){
        forwarderDestinations.add(df);
        fireTableDataChanged();
    }
    public void updateTable(){
        fireTableDataChanged();
    }

    public int getRowCount() {
	return forwarderDestinations.size();
    }

    public int getColumnCount() {
	return 4;
    }

    public Object getValueAt(int rowIndex, int columnIndex) {
	ForwarderDestination fd = forwarderDestinations.get(rowIndex);
	switch(columnIndex){
	    case 0:
		return fd.getIpAddress();
	    case 1:
		return fd.getPort();
            case 2:
                return fd.getStatus();
	    case 3:
		return System.currentTimeMillis() - fd.getLastByteTime();
	}
	return "no data for "+columnIndex;
    }
}
